package com.hsurosy.hsuchain.nft.api.order.response;

import com.hsurosy.hsuchain.nft.base.response.BaseResponse;
import lombok.Data;

import static com.hsurosy.hsuchain.nft.base.exception.BizErrorCode.DUPLICATED;

/**
 * 订单响应类
 *
 * @Author Hsu琛君珩
 * @Date 2024-10-04 17:07
 * @Description
 * @Version: v1.0.0
 */
@Data
public class OrderResponse extends BaseResponse {

    /**
     * 订单ID
     */
    private String orderId;

    /**
     * 流水ID
     */
    private String streamId;

    /**
     * 订单响应构建器类
     */
    public static class OrderResponseBuilder {

        private String orderId;
        private String streamId;

        /**
         * 设置订单ID
         *
         * @param orderId 订单ID
         * @return 构建器对象
         */
        public OrderResponseBuilder orderId(String orderId) {
            this.orderId = orderId;
            return this;
        }

        /**
         * 设置流水ID
         *
         * @param streamId 流水ID
         * @return 构建器对象
         */
        public OrderResponseBuilder streamId(String streamId) {
            this.streamId = streamId;
            return this;
        }

        /**
         * 构建成功的订单响应
         *
         * @return 订单响应对象
         */
        public OrderResponse buildSuccess() {
            OrderResponse orderResponse = new OrderResponse();
            orderResponse.setOrderId(orderId);
            orderResponse.setStreamId(streamId);
            orderResponse.setSuccess(true);
            return orderResponse;
        }

        /**
         * 构建重复的订单响应
         *
         * @return 订单响应对象，表示订单重复
         */
        public OrderResponse buildDuplicated() {
            OrderResponse orderResponse = new OrderResponse();
            orderResponse.setOrderId(orderId);
            orderResponse.setStreamId(streamId);
            orderResponse.setSuccess(true);
            orderResponse.setResponseCode(DUPLICATED.getCode());
            orderResponse.setResponseMessage(DUPLICATED.getMessage());
            return orderResponse;
        }

        /**
         * 构建失败的订单响应
         *
         * @param code 错误代码
         * @param msg  错误消息
         * @return 订单响应对象，表示失败
         */
        public OrderResponse buildFail(String code, String msg) {
            OrderResponse orderResponse = new OrderResponse();
            orderResponse.setOrderId(orderId);
            orderResponse.setStreamId(streamId);
            orderResponse.setSuccess(false);
            orderResponse.setResponseCode(code);
            orderResponse.setResponseMessage(msg);
            return orderResponse;
        }
    }
}
